package lyl.tree;

/**
 * 树从根到叶子节点的最大值
 */
public class BinaryTreeMathPathSum {

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    public int maxPathSum(TreeNode root){
        if(root == null){
            return 0;
        }
        int left = maxPathSum(root.left);
        int right = maxPathSum(root.right);
        return Math.max(0 , Math.max(left , right)) + root.val;
    }


}
